package com.lianniu.mgr.baseService.sysInfo.service.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import com.lianniu.mgr.base.BaseResult;
import com.lianniu.mgr.baseService.menu.dao.IMenuMapperDao;
import com.lianniu.mgr.baseService.menu.model.MenuVo;
import com.lianniu.mgr.baseService.sysInfo.dao.ISysInfoDao;
import com.lianniu.mgr.baseService.sysInfo.model.SysInfoVo;
import com.lianniu.mgr.baseService.sysInfo.service.ISysInfoService;
import com.lianniu.mgr.pagination.PaginationInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
 * @ClassName：SysInfoServiceImpl
 * @Description:系统管理

 * @Since: 2016年4月8日
 * @Version:0.1
 */
@Service
public class SysInfoServiceImpl implements ISysInfoService {
	private final static Logger logger = Logger.getLogger(SysInfoServiceImpl.class);
	@Resource
	ISysInfoDao sysInfoDao;
	
	@Autowired
	IMenuMapperDao menuMapper;
	/**
	 * 系统信息删除
	 * @param sysInfoVo
	 * @return
	 */
	@Transactional
	@Override
	public BaseResult deleteSysInfoById (List<String> ids){
		logger.info("deleteSysInfoById begin");
		logger.info("getMenuBySysId begin.");
		List<MenuVo> menuList=menuMapper.getMenuBySysId(ids);
		logger.info("getMenuBySysId end.");
		if(menuList!=null&&menuList.size()>0){
			logger.info("deleteSysInfoById end.");
			return BaseResult.fail("0003", "已有菜单，无法删除！");
		}else{
			int num = sysInfoDao.deleteSysInfoById(ids);
			logger.info("deleteSysInfoById end");
			return BaseResult.success(num);
		}
		
	}
	/**
	 * 系统信息修改
	 * @param sysInfoVo
	 * @return
	 */
	@Transactional
	@Override
	public BaseResult editSysInfoById(SysInfoVo sysInfoVo){
		logger.info("updateSysInfoById begin");
		int num =sysInfoDao.editSysInfoById(sysInfoVo);
		return BaseResult.success(num);
	}
	/**
	 * 系统信息录入
	 * @param sysInfoVo
	 * @return
	 */
	@Transactional
	@Override
	public BaseResult insertSysInfo(SysInfoVo sysInfoVo){
  	  	logger.info("insertSysInfo begin");
  	  	logger.info("insertSysInfo: input data check begin");
  	  	logger.info("id:"+sysInfoVo.getId());
  	  	logger.info("sysName"+sysInfoVo.getSysName());
  	  	logger.info("insertSysInfo: input data check end");
  	    return BaseResult.success(sysInfoDao.insertSysInfo(sysInfoVo));
	}
	/**
	 * 系统信息查询
	 * @param sysInfoVo
	 * @return
	 */
	@Override
	public BaseResult getSysInfoForPage(SysInfoVo sysInfoVo,PaginationInfo paginationInfo){
   	  	logger.info("getSysInfoForPage begin");
   	  	sysInfoVo.setPaginationInfo(paginationInfo);
	  	List<SysInfoVo> list = sysInfoDao.getSysInfoForPage(sysInfoVo);
	  	Map<String,Object> map=new HashMap<String,Object>();
	    map.put("total", paginationInfo.getTotalRecord());
	    map.put("curPage", paginationInfo.getCurPage());
	    map.put("rows", list);
	    logger.info("getSysInfoForPage end");
	  	return BaseResult.success(map);
	}
	/**
	 * 系统信息条数查询
	 * @param sysInfoVo
	 * @return
	 */
	@Override
	public BaseResult getSysInfoCount(SysInfoVo sysInfoVo){
		logger.info("getSysInfoCount begin");
		int num =sysInfoDao.getSysInfoCount(sysInfoVo);
		logger.info("getSysInfoCount end");
		return BaseResult.success(num);
	}
	/**
	 * 根据ID查询系统信息
	 */
	@Override
	public BaseResult getSysInfoById(SysInfoVo sysInfoVo) {
		logger.info("getSysInfoById begin");
		SysInfoVo vo = sysInfoDao.getSysInfoById(sysInfoVo);
		logger.info("getSysInfoById end");
		return  BaseResult.success(vo);
	}
	/**
	 * 倒叙查询系统序列最小的系统ID
	 */
	@Override
	public BaseResult getSysInfoByNum(SysInfoVo sysInfoVo) {
		logger.info("getSysInfoByNum begin");
		List<SysInfoVo> list = sysInfoDao.getSysInfoByNum(sysInfoVo);
		logger.info("getSysInfoByNum end");
		return BaseResult.success(list) ;
	}


}
